
import { ZDYpostMessage } from './utils.js';
// 延迟函数
function waitTimeOut(t = 1000) {
  return new Promise((resolve => {
    setTimeout(() => {
      resolve();
    }, t);
  }))
}

function closeBox() {
  let btns = $('.layui-layer-close')
  Array.from(btns).forEach(element => {
    element.click();
  });
}
function clickMMdl() {
  document.getElementById('mmdl_QieHuan').click()
}
async function autoInputAccount({ nationalTaxId, nationalTaxPass, nationalTaxAccount }) {
  document.querySelector('#shxydmOrsbh').value = nationalTaxId;
  document.querySelector('#userNameOrSjhm').value = nationalTaxAccount;
  document.querySelector('#passWord').value = nationalTaxPass;
}

async function loginStop() {
  if (window.location.pathname === '/xxmh/') {
    await waitTimeOut()
    document.getElementById('kxText').click()
  }

  if (/\/sso\/login/g.test(window.location.pathname)) {
    await waitTimeOut()
    document.getElementById('mmdl_QieHuan').click();
  }

  setTimeout(() => {
      ZDYpostMessage({ event: 'getBaseInfo' });
    }, 100)
}



export {
  closeBox,
  clickMMdl,
  autoInputAccount,
  waitTimeOut,
  loginStop
};